<?php

namespace App\Service;

use App\Models\Base\OrderChargeLevel;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;

/**
 * 玩家充值逻辑.
 */
class PayService
{
    /**
     * [getTodayAccount 当日充值金额].
     *
     * @Author   王文凡
     * @DateTime 2018-03-07
     *
     * @version  1.0
     *
     * @return [type] [description]
     */
    public function getTodayAccount()
    {
        //当日时间戳
        $today = Carbon::today()->timestamp;
        $amount = DB::table('orders')->where([['order_time', '>=', $today], ['status', 1]])->sum('amount');

        return is_null($amount) ? 0 : $amount;
    }

    /**
     * [getTodayPayNum 当日充值玩家数量].
     *
     * @Author   王文凡
     * @DateTime 2018-03-07
     *
     * @version  1.0
     *
     * @param    string|array 条件
     *
     * @return int
     */
    public static function getTodayPayNum($where = '')
    {
        $today = Carbon::today()->timestamp;
        $db = DB::table('orders')
            ->selectRaw('userid')
            ->where([['order_time', '>=', $today], ['status', 1]]);
        if (is_array($where) && $where) {
            $db = $db->whereIn('userid', arrayNumericString($where));
        }
        $num = $db->groupBy('userid')->get()->count();

        return $num;
    }

    /**
     * 充值档位金额集合.
     *
     * @return array
     */
    public static function getTopUpGears()
    {
        return OrderChargeLevel::all()->pluck('price')->all();
    }
}
